<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test1"></div>
    <script src="../lib/react.development.js"></script>
    <script src="../lib/react-dom.development.js"></script>
    <script src="../lib/babel.min.js"></script>
    <script src="../lib/prop-types.js"></script>
    <script type="text/babel">
        class FormComponent extends React.Component{
            constructor(props){
                super(props)
                this.handleClick = this.handleClick.bind(this)
                this.handleChange = this.handleChange.bind(this)
                this.state = {
                    pwd: ''
                }
            }
            handleClick(e){
                alert(`用户名为${this.input.value}，密码为${this.state.pwd}`)
                e.preventDefault()
            }
            handleChange(e){
                this.setState({
                    pwd: e.target.value
                })
            }
            render(){
                return (
                    <form action="test" method="GET">
                        <label htmlFor="user">用户名：</label><input id="user" type="text" placeholder="用户名" ref={input=>this.input=input}/>
                        <label htmlFor="password">密码：</label><input id="password" type="text" placeholder="密码" onChange={this.handleChange}/>
                        <button onClick={this.handleClick}>提交</button>
                    </form>
                )
            }
        }
        ReactDOM.render(<FormComponent />, document.getElementById('test1'))
    </script>
</body>
</html>